/*
 * @Author: xiaoyan
 * @Date: 2021-09-28 16:01:07
 * @LastEditors: xiaoyan
 * @LastEditTime: 2021-09-28 16:27:08
 * @Description: 
 * @FilePath: \vue3-ts-demo\src\utils\index.ts
 */
//时间格式化
export const dateFormat = (str:string,format = "yyyy-MM-dd")=>{
    if(!str) return "";
    const date = new Date(str);
    const year = date.getFullYear();
    const month = replenishZero(date.getMonth() + 1);
    const day = replenishZero(date.getDate());
    const hour = replenishZero(date.getHours());
    const minute = replenishZero(date.getMinutes());
    const second = replenishZero(date.getSeconds());
    if(format === "yyyy-MM-dd HH:mm:ss"){
        return `${year}-${month}-${day} ${hour}:${minute}:${second}`;
    }else{
        return `${year}-${month}-${day}`;
    }
}
//一位数补0
export const replenishZero = (num:any)=>{
    if(!num) return "00"
    const str = num.toString();
    if(str.length === 1){
        return "0"+str;
    }else{
        return str;
    }
}
